﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abp.Web
{
    public class Pagination
    {
        /// <summary>
        /// 总记录数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 当前页
        /// </summary>
        public int Page { get; set; }
        /// <summary>
        /// 分页大小
        /// </summary>
        public int Rows { get; set; }
        /// <summary>
        /// 关键词搜索
        /// </summary>
        public string Keywords { get; set; }
        /// <summary>
        /// 排序字段
        /// </summary>
        public string Sort { get; set; }
        /// <summary>
        /// 排序方向
        /// </summary>
        public string Order { get; set; }


        public Pagination()
        {
            this.Page = 1;
            this.Rows = 10;
            this.Keywords = string.Empty;

        }
        /// <summary>
        /// 获取开始记录数
        /// </summary>
        /// <returns></returns>
        public int GetStartRecordIndex()
        {
            int start = (this.Page - 1) * this.Rows;
            return start < 0 ? 0 : start;
        }
        /// <summary>
        /// 获取结束记录数
        /// </summary>
        /// <returns></returns>
        public int GetEndRecordIndex()
        {
            int end = this.Page * this.Rows;
            if (end <= 0)
                end = this.Rows;
            return end;
        }
        /// <summary>
        /// 获取分页大小
        /// </summary>
        /// <returns></returns>
        public int GetPageSize()
        {
            if (this.Rows < 1)
                return 10;
            return this.Rows;
        }

        public string GetOrderBy()
        {
            return this.Sort + " " + this.Order;
        }
    }
}
